import { login } from '@/api/user'
import { getToken, setToken } from '@/utils/auth'

export default {
  namespaced: true,
  state: {
    userToken: getToken() || ''
  },
  mutations: {
    setUserToken(state, payload) {
      state.userToken = payload
      setToken(payload)
    }
  },
  actions: {
    async userLogin(txc, payload) {
      const token = await login(payload)
      txc.commit('setUserToken', token)
    }
  }
}
